//
//  ViewController.swift
//  swift_review
//
//  Created by Andrew on 2024/11/24.
//

import UIKit

class ViewController: UIViewController {
    
    var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        setupUI()
        
        //添加引号
        YMCharacter.changeString(sign: "sdlfo23i0sdfs0jljsd=")
    }
    
    func setupUI() {
        tableView = UITableView(frame: .zero)
        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
        
        //注册cell
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.classID)
        
        //设置约束
        NSLayoutConstraint.activate([
            tableView.topAnchor.constraint(equalTo: view.topAnchor),
            tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        ])
    }
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: UITableViewCell.classID, for: indexPath)
        switch indexPath.row {
        case 0:
            cell.textLabel?.text = "collectionView-nor"
        case 1:
            cell.textLabel?.text = "collectionView-runHeader"
        case 2:
            cell.textLabel?.text = "collectionView-picker"
        case 3:
            cell.textLabel?.text = "TextField"
        case 4:
            cell.textLabel?.text = "TextView"
        case 5:
            cell.textLabel?.text = "Network"
        case 6:
            cell.textLabel?.text = "uploadImage"
        case 7:
            cell.textLabel?.text = "DatePicker"
        case 8:
            cell.textLabel?.text = "压缩/解压"
        case 9:
            cell.textLabel?.text = "crash"
        default:
            cell.textLabel?.text = "Row \(indexPath.row)"
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            let vc = YMCollectionNorVC()
            navigationController?.pushViewController(vc, animated: true)
            break
        case 1:
            let vc = YMCollectionRunVC()
            navigationController?.pushViewController(vc, animated: true)
        case 2:
            let vc = YMPickerPhotosVC()
            navigationController?.pushViewController(vc, animated: true)
        case 3:
            let vc = YMTextFieldVC()
            navigationController?.pushViewController(vc, animated: true)
        case 4:
            let vc = YMTextViewVC()
            navigationController?.pushViewController(vc, animated: true)
        case 5:
            let vc = YMNetworkVC()
            navigationController?.pushViewController(vc, animated: true)
        case 6:
            let vc = ImageUploaderVC()
            navigationController?.pushViewController(vc, animated: true)
        case 7:
            let vc = DatePickerViewController()
            navigationController?.pushViewController(vc, animated: true)
        case 8:
            let vc = YMCompressionVC()
            navigationController?.pushViewController(vc, animated: true)
        case 9:
            let vc = YMLogViewController()
            navigationController?.pushViewController(vc, animated: true)
        default:
            break
        }
    }
}

